﻿using System;
using System.Collections.Generic;
using NUnit.Framework;
using Selenium;

namespace time
{
    [TestFixture]
    internal class webview
    {
        Selenium.ISelenium selenium;

        [Test]
        public void t1()
        {
            List<string> ls = common.FileHelper.readSingleline("webview.txt");
            foreach (var item in ls)
            {
                view(item);
            }
        }

        private void view(string url)
        {
            selenium = new DefaultSelenium("localhost", 4444, "*chrome", url);
            selenium.Start();
            selenium.Open(url);
            selenium.WindowMaximize();

            //selenium.WaitForPageToLoad("30000");
            System.Threading.Thread.Sleep(2000);

            //var v=selenium.GetValue("//a");
            //string script = s1();
            //string r=selenium.GetEval(script);
            //Console.WriteLine(r);

            string stra = common.JsHelp.geta();
            String[] a = selenium.GetEval(stra).Split(','); // Split the string.

            foreach (var item in a)
            {
                try
                {
                    selenium.Open(item);
                    System.Threading.Thread.Sleep(4000);
                    //selenium.GoBack();
                }
                catch (Exception ee)
                {
                    common.LogHelp.writelog(ee.ToString());
                    continue;
                }
            }

            //Console.WriteLine("hello");
        }

        public static string s1()
        {
            string s = "var a='1';";
            //s += "a.toString();";
            return s;
        }

        //public static String[] getAllCheckboxIds()
        //{
        //    String script = "var inputId  = new Array();";// Create array in java script.
        //    script += "var cnt = 0;"; // Counter for check box ids.
        //    script += "var inputFields  = new Array();"; // Create array in java script.
        //    script += "inputFields = window.document.getElementsByTagName('input');"; // Collect input elements.
        //    script += "for(var i=0; i<inputFields.length; i++) {"; // Loop through the collected elements.
        //    script += "if(inputFields[i].id !=null " +
        //    "&& inputFields[i].id !='undefined' " +
        //    "&& inputFields[i].getAttribute('type') == 'checkbox') {"; // If input field is of type check box and input id is not null.
        //    script += "inputId[cnt]=inputFields[i].id ;" + // Save check box id to inputId array.
        //    "cnt++;" + // increment the counter.
        //    "}" + // end of if.
        //    "}"; // end of for.
        //    script += "inputId.toString();";// Convert array in to string.
        //    String[] checkboxIds = selenium.getEval(script).split(","); // Split the string.
        //    return checkboxIds;
        //}
    }
}